﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;

namespace ibba.src.sl.componentes
{
    public class CustomContentPanel : ContentControl
    {
        public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register("Header", typeof(string), typeof(CustomContentPanel), null);
        public static readonly DependencyProperty HeaderPaddingProperty = DependencyProperty.Register("HeaderPadding", typeof(Thickness), typeof(CustomContentPanel), null);
        //public static readonly DependencyProperty HeaderTemplateProperty = DependencyProperty.Register("HeaderTemplate", typeof(UIElement), typeof(CustomContentPanel), null);
        public static readonly DependencyProperty CorderRadiusProperty = DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(CustomContentPanel), null);
        public static readonly DependencyProperty BackgroundHeaderProperty = DependencyProperty.Register("BackgroundHeader", typeof(Brush), typeof(CustomContentPanel), null);

        public CustomContentPanel()
        {
            this.DefaultStyleKey = typeof(CustomContentPanel); //Definindo o Tema Padrão do arquivo Generic.xaml
        }

        //public UIElement HeaderTemplate
        //{
        //    get { return (UIElement)this.GetValue(HeaderTemplateProperty); }
        //    set { this.SetValue(HeaderTemplateProperty, value); }
        //}

        public string Header
        {
            get { return (string)this.GetValue(HeaderProperty); }
            set { this.SetValue(HeaderProperty, value); }
        }

        public Thickness HeaderPadding
        {
            get { return (Thickness)this.GetValue(HeaderPaddingProperty); }
            set { this.SetValue(HeaderPaddingProperty, value); }
        }        

        public CornerRadius CornerRadius
        {
            get { return (CornerRadius)GetValue(CorderRadiusProperty); }
            set { SetValue(CorderRadiusProperty, value); }
        }

        public Brush BackgroundHeader
        {
            get { return (Brush)GetValue(BackgroundHeaderProperty); }
            set { SetValue(BackgroundHeaderProperty, value); }
        }
                
    }



    public class HeaderVisibilityConverter : IValueConverter
    {

        #region IValueConverter Members

        public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                return (Visibility)(string.IsNullOrEmpty(value.ToString()) ? Visibility.Collapsed : Visibility.Visible);
            }
            catch (System.Exception)
            {
                return Visibility.Collapsed;
            }

        }

        public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                return (Visibility)(string.IsNullOrEmpty(value.ToString()) ? Visibility.Collapsed : Visibility.Visible);
            }
            catch (System.Exception)
            {
                return Visibility.Collapsed;
            }
        }

        #endregion
    }
}
